package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BdmExpensesDetail;
import com.ruoyi.system.service.IBdmExpensesDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 支出明细Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/system/detail")
public class BdmExpensesDetailController extends BaseController
{
    @Autowired
    private IBdmExpensesDetailService bdmExpensesDetailService;

    /**
     * 查询支出明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BdmExpensesDetail bdmExpensesDetail)
    {
        startPage();
        List<BdmExpensesDetail> list = bdmExpensesDetailService.selectBdmExpensesDetailList(bdmExpensesDetail);
        return getDataTable(list);
    }

    /**
     * 导出支出明细列表
     */
    @Log(title = "支出明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdmExpensesDetail bdmExpensesDetail)
    {
        List<BdmExpensesDetail> list = bdmExpensesDetailService.selectBdmExpensesDetailList(bdmExpensesDetail);
        ExcelUtil<BdmExpensesDetail> util = new ExcelUtil<BdmExpensesDetail>(BdmExpensesDetail.class);
        util.exportExcel(response, list, "支出明细数据");
    }

    /**
     * 获取支出明细详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bdmExpensesDetailService.selectBdmExpensesDetailById(id));
    }

    /**
     * 新增支出明细
     */
    @Log(title = "支出明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdmExpensesDetail bdmExpensesDetail)
    {
        return toAjax(bdmExpensesDetailService.insertBdmExpensesDetail(bdmExpensesDetail));
    }

    /**
     * 修改支出明细
     */
    @Log(title = "支出明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdmExpensesDetail bdmExpensesDetail)
    {
        return toAjax(bdmExpensesDetailService.updateBdmExpensesDetail(bdmExpensesDetail));
    }

    /**
     * 删除支出明细
     */
    @Log(title = "支出明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bdmExpensesDetailService.deleteBdmExpensesDetailByIds(ids));
    }
}
